package com.demo.java.OD551_600.OD553;

import java.util.Scanner;
import java.util.*;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【比赛(B卷-100分)】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/146533157
 */
public class OdMain {
    public static void main(String[] args) {
        // 处理输入
        Scanner in = new Scanner(System.in);
        String[] strings1 = in.nextLine().split(",");
        int m = Integer.valueOf(strings1[0]); // 评委数量
        int n = Integer.valueOf(strings1[1]); // 选手数量

        // 判断评委数量和选手数量是否在有效范围内
        if (m < 3 || m > 10 || n < 3 || n > 100) {
            System.out.println("-1");
            return;
        }

        int[][] scores = new int[m][n]; // 用于存储每个选手的每个评委的分数
        for (int i = 0; i < m; i++) {
            String input_str = in.nextLine();
            String[] tmp2 = input_str.split(",");
            int[] nums = new int[tmp2.length];
            for (int x = 0; x < tmp2.length; x++) {
                nums[x] = Integer.parseInt(tmp2[x]);
            }
            for (int j = 0; j < n; j++) {
                scores[i][j] = nums[j];
                if (scores[i][j] > 10 || scores[i][j] < 1) {
                    System.out.println("-1");
                    return;
                }
            }
        }

        ArrayList<Player> playerList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int total = 0;
            ArrayList<Integer> scoreList = new ArrayList<Integer>();
            for (int j = 0; j < m; j++) {
                scoreList.add(scores[j][i]);
                total += scores[j][i];
            }
            playerList.add(new Player(i, total, scoreList));
        }

        // 排序选手
        Collections.sort(playerList, new Comparator<Player>() {
            @Override
            public int compare(Player p1, Player p2) {
                // 比较总分
                if (p1.total != p2.total) {
                    return p2.total - p1.total; // 总分较高的排前面
                } else {
                    // 总分相同，进一步比较每个评委的评分
                    ArrayList<Integer> playerList = p1.scores;
                    ArrayList<Integer> scoreList = p2.scores;
                    for (int i = 10; i > 0; i--) {
                        if (single(playerList, i) < single(scoreList, i)) {
                            return -1; // 更高评分的排前面
                        }
                    }
                }
                return 0;
            }
        });

        // 输出排名前三的选手编号
        for (int i = 0; i < 3; i++) {
            if (i == 2) {
                System.out.println(playerList.get(i).index + 1);
            } else {
                System.out.print(playerList.get(i).index + 1 + ",");
            }
        }
    }

    // 计算某个分数出现的次数
    public static int single(ArrayList<Integer> list, int count) {
        int ret = 0;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) == count) {
                ret++;
            }
        }
        return ret;
    }
}

// 玩家类，保存选手信息
class Player {
    int index; // 选手编号
    int total; // 总分
    ArrayList<Integer> scores; // 选手的各项评分

    public Player(int index, int total, ArrayList<Integer> scores) {
        this.index = index;
        this.total = total;
        this.scores = scores;
    }
}